﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bintje.bintje;

namespace Bintje
{
    public class ImageFilter
    {
        #region Fields

        private int m_id;
        private int m_innerRadius;
        private int m_maximumNumber;
        private int m_outerRadius;
        private int?[] m_trailstoexclude; 
        private imageoSession m_session;

        #endregion

        #region Properties

        public int Id
        {
            get { return m_id; }
            set { m_id = value; }
        }

        public int InnerRadius
        {
            get { return m_innerRadius; }
            set { m_innerRadius = value; }
        }

        public int MaximumNumber
        {
            get { return m_maximumNumber; }
            set { m_maximumNumber = value; }
        }

        public int OuterRadius
        {
            get { return m_outerRadius; }
            set { m_outerRadius = value; }
        }

        public int?[] Trailstoexclude
        {
            get { return m_trailstoexclude; }
            set { m_trailstoexclude = value; }
        } 

        #endregion

        #region ctor

        public ImageFilter(imageoSession session)
        {
            m_session = session;
        } 

        #endregion

        #region Methods

        public bool Search(out IList<Trail> trails, out IList<WayPointWrapper> waypoints)
        {
            trails = new List<Trail>();
            waypoints = new List<WayPointWrapper>();
            similarImageResponse response = API.instance.getSimilarImages(GetRequest());
            if (null != response && response.status == API.RESPONSE_SUCCESS)
            {
                if (null != response.trails)
                {
                    trails = new List<Trail>(response.trails.Length);
                    for (int i = 0; i < response.trails.Length; i++)
                    {
                        Trail trail = new Trail(response.trails[i]);
                        trails.Add(trail);
                    }
                }
                if (null != response.waypoints) 
                {
                    waypoints = new List<WayPointWrapper>(response.waypoints.Length);
                    for (int i = 0; i < response.waypoints.Length; i++)
                    {
                        WayPointWrapper waypoint = new WayPointWrapper(response.waypoints[i]);
                        waypoints.Add(waypoint);
                    }
                }
                return true;
            }
            return false;
        }

        private similarImageRequest GetRequest()
        {
            similarImageRequest request = new similarImageRequest();
            request.imageId = m_id;
            request.innerRadius = m_innerRadius;
            request.maximumNumber = m_maximumNumber;
            request.outerRadius = m_outerRadius;
            request.session = m_session;
            request.trailstoexclude = m_trailstoexclude;
            return request;
        } 

        #endregion
    }
}
